package video.com.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Configuration
public class RedisUtils {

    public static RedisTemplate<String , Object> redis;

    @Autowired
    public void setRedisTemplate(RedisTemplate<String , Object> redisTemplate){
        this.redis = redisTemplate;
    }

    @PostConstruct //此注解表示构造时赋值
    public void redisTemplate() {
        redis.setDefaultSerializer(new StringRedisSerializer());
        redis.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        redis.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
        redis.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());

    }

    public static void remove(String key){
        redis.delete(key);
    }
}
